import { useRouterNavigation } from "@/router/utils";
import { ImageViewer } from "@/components/common/ImageViewer";
import { dealDataExcept } from "@/utils/common";
import { getDrkCount } from "../../../common";

export function useStoreDetil() {
  // 返回上一页
  const { go } = useRouterNavigation();
  function goBack(n) {
    go(n);
  }

  const columns: TableColumnList = [
    {
      label: "商品编码",
      prop: "goodsCode",
      minWidth: "120px"
    },
    {
      label: "商品名称",
      prop: "goodsName",
      width: "180px",
      cellRenderer: ({ row }) => (
        <div class="flex items-center">
          <ImageViewer radius="8px" src={row.specImageJson} />
          <span class="ml-1 truncate">{row.goodsName}</span>
        </div>
      )
    },
    {
      label: "规格编码",
      prop: "specCode",
      minWidth: "120px"
    },
    {
      label: "规格名称",
      prop: "specName",
      minWidth: "120px",
      formatter: ({ specName }) => specName || "--"
    },
    {
      label: "备货数量",
      prop: "amount",
      minWidth: "100px"
    },
    {
      label: "商品单价",
      prop: "buyPrice",
      minWidth: "100px",
      formatter: ({ buyPrice }) => dealDataExcept(buyPrice)
    },
    {
      label: "金额",
      prop: "orderItemPrice",
      minWidth: "100px",
      formatter: ({ orderItemPrice }) => dealDataExcept(orderItemPrice)
    },
    {
      label: "分摊金额",
      prop: "avgPrice",
      minWidth: "100px",
      formatter: ({ avgPrice }) => dealDataExcept(avgPrice) || "--"
    },
    {
      label: "分摊后单价",
      prop: "avgBuyPrice",
      minWidth: "100px",
      formatter: ({ avgBuyPrice }) => dealDataExcept(avgBuyPrice) || "--"
    },
    {
      label: "分摊后总价",
      prop: "avgOrderItemPrice",
      minWidth: "100px",
      formatter: ({ avgOrderItemPrice }) =>
        dealDataExcept(avgOrderItemPrice) || "--"
    },
    {
      label: "已入库数量",
      prop: "storeAmount",
      minWidth: "100px"
    },
    {
      label: "待入库数量",
      minWidth: "100px",
      formatter: row => getDrkCount(row)
    }
  ];

  return {
    goBack,
    columns
  };
}
